package com.sunrise.generico.entidade;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import lombok.Getter;
import lombok.Setter;

import org.hibernate.validator.constraints.NotEmpty;

import com.sunrise.generico.entidade.iface.EntidadeManter;
import com.sunrise.generico.enums.TipoFrequencia;

@Entity
@Table(name = "despesa")
public class Despesa implements EntidadeManter {


	/**
	 * 
	 */
	private static final long serialVersionUID = 457965482031545761L;
	@Id
	@SequenceGenerator(name="pk_sequence",sequenceName="despesa_id_seq", allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="pk_sequence")
	@Column
	@Getter @Setter
	private Long id;
	
	@NotEmpty( message="{despesaObrigatorio}")
	@Column(name = "nome", length = 60, nullable = false)
	@Getter @Setter
	private String nome;

	@NotNull
	@Getter @Setter
	@OneToOne
	private Conta conta;
	
	@Getter @Setter
	@Column(name = "valor")
	private BigDecimal valor;
	
	@NotNull
	@Getter @Setter
	@OneToOne
	private CategoriaFinanceira categoriaFinanceira;
	
	@NotNull
	@Getter @Setter
	@Column(name = "dataLancamento")
	private Date dataLancamento;
	
	@Getter @Setter
	@Column(name = "dataCadastro")
	private Date dataCadastro;
	
	@Getter @Setter
	@OneToOne
	private Usuario responsavel;
	
	@Column(name = "recorrencia")
	@Getter @Setter
	private Boolean recorrencia;
	
	@Column(name = "qtdRecorrencia")
	@Getter @Setter
	private Integer qtdRecorrencia;
	
	@Enumerated
	@Getter @Setter
	private TipoFrequencia tipoFrequencia;
	
	@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true)
	@JoinColumn(name = "despesa_id")
	@Getter @Setter
	private Collection<Recorrencia> recorrencias;
	
	@Column(name = "ativo")
	@Getter @Setter
	private Boolean ativo;

}
